package com.ychen.ruijee.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ychen.ruijee.bean.Orders;
import com.ychen.ruijee.common.R;
import com.ychen.ruijee.service.OrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author ychen@gotop.cn
 * @date 2024-06-08 23:20
 */

@RestController
@RequestMapping("/order")
public class OrderController {
    @Resource
    private OrderService orderService;

    /**
     * 下单实现
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public R<String> submitOrder(@RequestBody Orders orders){
        boolean flag = orderService.submitOrder(orders);
        return flag ? R.success("下单成功") : R.error("下单失败");
    }

    /**
     * 订单分页查询展示
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/userPage")
    public R<Page<Orders>> pageInfOrder(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "5") Integer pageSize){
        Page<Orders> result = orderService.pageInfOrder(page,pageSize);
        return R.success(result);

    }

}
